/**
 * 
 * Copyright 2009 Marco Speranza <marco.speranza79@gmail.com>
 *    
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *   
 * http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.commons.database.util.jquerycreator;

import java.sql.Clob;
import java.sql.Timestamp;
import java.sql.Types;

// TODO: Auto-generated Javadoc
/**
 * Classe bean che rappresenta i tipi ammessi.
 * 
 * I valori ammessi sono:
 * 
 * <pre>
 * BIT
 * TINYINT
 * SMALLINT
 * INTEGER
 * BIGINT
 * FLOAT
 * REAL
 * DOUBLE
 * NUMERIC
 * DECIMAL
 * CHAR
 * VARCHAR
 * LONGVARCHAR
 * DATE
 * TIME
 * TIMESTAMP
 * BINARY
 * VARBINARY
 * LONGVARBINARY
 * NULL
 * OTHER
 * JAVA_OBJECT
 * DISTINCT
 * STRUCT
 * ARRAY
 * BLOB
 * CLOB
 * REF
 * DATALINK
 * BOOLEAN
 * </pre>
 * 
 * @author Marco Speranza
 */
public class DataBaseQueryCreatorBean {

    /** The position. */
    private int position = 0;

    /** The value. */
    private Object value = null;

    /** The type. */
    private int type;

    /**
     * The Constructor.
     * 
     * @param value
     *            the value
     */
    public DataBaseQueryCreatorBean(Object value) {
	this(value, getType(value));
    }

    /**
     * Gets the type.
     * 
     * @param value
     *            the value
     * 
     * @return the type
     */
    private static int getType(Object value) {

	if (value instanceof String) {
	    return Types.VARCHAR;
	} else if (value instanceof Timestamp) {
	    return Types.TIMESTAMP;
	} else if (value instanceof Integer) {
	    return Types.INTEGER;
	} else if (value instanceof Clob) {
	    return Types.CLOB;
	} else if (value == null) {
	    return Types.NULL;
	} else {
	    throw new IllegalArgumentException(
		    " Value type unknown. Value must be a instance of java.lang.Integer, java.sql.Timestamp, java.lang.String, null. Actual argument: "
			    + value);
	}
    }

    /**
     * Crea una instanza della classe.
     * 
     * @param value
     *            il valore da utilizzare per riempire al quesy
     * @param type
     *            il tipo sql che deve essere inserito. <br>
     *            i valori accettati sono <code>java.sql.Types</code>
     */
    public DataBaseQueryCreatorBean(Object value, int type) {
	super();
	this.value = value;
	this.type = type;
    }

    /**
     * Gets the position.
     * 
     * @return the position
     */
    public int getPosition() {
	return position;
    }

    /**
     * Sets the position.
     * 
     * @param position
     *            the new position
     */
    public void setPosition(int position) {
	this.position = position;
    }

    /**
     * Gets the type.
     * 
     * @return the type
     */
    public int getType() {
	return type;
    }

    /**
     * Sets the type.
     * 
     * @param type
     *            the new type
     */
    public void setType(int type) {
	this.type = type;
    }

    /**
     * Gets the value.
     * 
     * @return the value
     */
    public Object getValue() {
	return value;
    }

    /**
     * Sets the value.
     * 
     * @param value
     *            the new value
     */
    public void setValue(Object value) {
	this.value = value;
    }

}
